# 9 回文数
# https://leetcode.cn/problems/palindrome-number/
# Date: 2024/10/28
def isPalindrome(x: int) -> bool:
    """我的写法"""
    s = str(x)
    n = len(s)
    if n < 2:
        return True
    for i in range(n // 2):
        if s[i] != s[n - i - 1]:
            return False
    return True


def isPalindrome_opt(x: int) -> bool:
    if x < 0:
        return False
    x_str = str(x)
    if x_str == x_str[::-1]:
        return True
    return False


if __name__ == '__main__':
    print(isPalindrome(123))
    print(isPalindrome(121))
    print(isPalindrome(1221))
    print(isPalindrome(-1221))
